#include <iostream.h>
#include <string.h>
#include <stdio.h>

	long	tot,x;

main()
{
	char	city[50];
	char	classtype;

	cin>>city;
	while (city[0]!='#')
	{
    	tot=0;
		while (city[0]!='0')
		{
			cin>>city>>x>>classtype;
			switch (classtype) 
			{
				case 'F' :
				 tot+=x*2; break;
				case 'B' :	
				 tot+=x+(x+1)/2; break;
				case 'Y' :
				 if (x<=500) tot+=500; else tot+=x; break;
			}
			cin>>city;
		}
		printf("%ld\n",tot);
		cin>>city;
	}

	return 0;
}
